how to find the angle of 2 coordinates java

217

how to find the angle of 2 coordinates java -

public double getAngleFromPoint(Point firstPoint, Point secondPoint) {

    if((secondPoint.x > firstPoint.x)) {//above 0 to 180 degrees

        return (Math.atan2((secondPoint.x - firstPoint.x), (firstPoint.y - secondPoint.y)) * 180 / Math.PI);

    }
    else if((secondPoint.x < firstPoint.x)) {//above 180 degrees to 360/0

        return 360 - (Math.atan2((firstPoint.x - secondPoint.x), (firstPoint.y - secondPoint.y)) * 180 / Math.PI);

    }//End if((secondPoint.x > firstPoint.x) && (secondPoint.y <= firstPoint.y))

    return Math.atan2(0 ,0);

}//End public float getAngleFromPoint(Point firstPoint, Point secondPoint)

Comments

Submit
0 Comments